package com.ldq.imooc.basics.io;

import java.io.File;
import java.io.IOException;

/**
 * @Author : 李道泉
 * @Description :
 * @Date : 2018/4/4 15:40
 * @Modified by :
 */
public class FileUtils {

    public static void listDirectory(File dir) throws IOException {

        if (!dir.exists()) {

            throw new IllegalArgumentException("目录" + dir + "不存在");
        }

        if (!dir.isDirectory()) {

            throw new IllegalArgumentException(dir + "不是目录");
        }

        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {

                if (file.isDirectory()) {
                    listDirectory(file);
                    System.out.println(file);
                } else {
                    System.out.println(file);
                }
            }
        }
    }
}
